<cfsilent>
	<cfset showMilestoneGoalID = $.request.getValue('showMilestoneGoalID') />
	<cfset showActionGoalID = $.request.getValue('showActionGoalID') /> 
	<!--- determine which to show --->
	<cfset past = false />
	<cfset present = false />
	<cfset future = false />
	<cfset time_frame = $.request.getValue('time_frame') />
	<cfif time_frame contains 'past'>
		<cfset past = true />
	</cfif>
	<cfif time_frame contains 'present'>
		<cfset present = true />
	</cfif>
	<cfif time_frame contains 'future'>
		<cfset future = true />
	</cfif>
	<cfif time_frame eq "">
		<cfset present = true />
		<cfset future = true />
	</cfif>
	<cfset past_goals = $.run.it('goalService.getgoals',{time_frame='past'}) />
	<cfset present_goals = $.run.it('goalService.getgoals',{time_frame='present'}) />
	<cfset future_goals = $.run.it('goalService.getgoals',{time_frame='future'}) />
	<cfset category_count = 0 />
	<cfif past and past_goals.recordcount gt 0><cfset category_count++ /></cfif>
	<cfif present and present_goals.recordcount gt 0><cfset category_count++ /></cfif>
	<cfif future and future_goals.recordcount gt 0><cfset category_count++ /></cfif>

</cfsilent>

<cfoutput>
	<cfsavecontent variable="page">
		<div class="header variable-width">
			<i class="fa fa-home" onclick="Main.nav('home');"></i>
			<div class="header-title">
				Goals and Milestones
				<div>
					<input type="checkbox" name="time_frame" value="past" <cfif past>checked</cfif> onchange="Goals.reloadPage();" /> Past<cfif past_goals.recordcount gt 0>(#past_goals.recordcount#)</cfif>
					<input type="checkbox" name="time_frame" value="present" <cfif present>checked</cfif> onchange="Goals.reloadPage();" /> Present<cfif present_goals.recordcount gt 0>(#present_goals.recordcount#)</cfif>
					<input type="checkbox" name="time_frame" value="future" <cfif future>checked</cfif> onchange="Goals.reloadPage();" /> Future<cfif future_goals.recordcount gt 0>(#future_goals.recordcount#)</cfif>
				</div>
			</div>
			#$.render.img(path="craftivity/widget_icons/trophy.png")#</br>
			<button id="add_goal" class="red" style="position:absolute;right:2px;bottom:2px;" onclick="Goals.showAddGoal(this);">Add Goal</button>
		</div>
		
		<div id="new_goal" style="display:none;">
			#$.run.it('goalView.renderGoal',{
				goalID="",
				name="",
				description="",
				year=""
			})#
		</div>
		
		#$.run.it('optionView.renderOption',{key="workweekCategories"})#
		
		<cfif past_goals.recordcount gt 0 and category_count gt 1 and past>
			<div class="time_frame_header header variable-width">
				Past Goals
			</div>
		</cfif>
		
		<cfif past>
			<cfloop query="past_goals">
				#$.run.it('goalView.renderGoal',{
					goalID=past_goals.id,
					name=past_goals.name,
					description=past_goals.description,
					milestone_count=past_goals.milestone_count,
					action_count=past_goals.action_count,
					start=$.date.applyLocalization(past_goals.goal_start),
					end=$.date.applyLocalization(past_goals.goal_stop),
					showMilestoneGoalID=showMilestoneGoalID,
					showActionGoalID=showActionGoalID,
					time_frame=time_frame,
					past=true,
					abandoned=past_goals.abandoned,
					measurable=past_goals.measurable,
					unit=past_goals.unit,
					target_count=past_goals.target_count
				})#
			</cfloop>
		</cfif>
		
		<cfif present_goals.recordcount gt 0 and category_count gt 1 and present>
			<div class="time_frame_header header variable-width">
				Present Goals
			</div>
		</cfif>
		
		<cfif present>

			<cfloop query="present_goals">
				#$.run.it('goalView.renderGoal',{
					goalID=present_goals.id,
					name=present_goals.name,
					description=present_goals.description,
					milestone_count=present_goals.milestone_count,
					action_count=present_goals.action_count,
					start=$.date.applyLocalization(present_goals.goal_start),
					end=$.date.applyLocalization(present_goals.goal_stop),
					showMilestoneGoalID=showMilestoneGoalID,
					showActionGoalID=showActionGoalID,
					time_frame=time_frame,
					abandoned=present_goals.abandoned,
					measurable=present_goals.measurable,
					unit=present_goals.unit,
					target_count=present_goals.target_count
				})#
			</cfloop>
		</cfif>

		
		<cfif future_goals.recordcount gt 0 and category_count gt 1 and future>
			<div class="time_frame_header header variable-width">
				Future Goals
			</div>
		</cfif>
		
		<cfif future>
			<cfloop query="future_goals">
				#$.run.it('goalView.renderGoal',{
					goalID=future_goals.id,
					name=future_goals.name,
					description=future_goals.description,
					milestone_count=future_goals.milestone_count,
					action_count=future_goals.action_count,
					start=$.date.applyLocalization(future_goals.goal_start),
					end=$.date.applyLocalization(future_goals.goal_stop),
					showMilestoneGoalID=showMilestoneGoalID,
					showActionGoalID=showActionGoalID,
					time_frame=time_frame,
					future=true,
					abandoned=future_goals.abandoned,
					measurable=future_goals.measurable,
					unit=future_goals.unit,
					target_count=future_goals.target_count
				})#
			</cfloop>
		</cfif>
	</cfsavecontent>
	
	#application.v.craftivityView.renderPage(page)#
	
</cfoutput>